<template>
    <div>
        <van-nav-bar title="标题" left-text="返回" right-text="按钮" left-arrow @click-left="onClickLeft" />
        <van-address-list v-model="chosenAddressId" :list="list" default-tag-text="默认" @add="onAdd" @edit="onEdit"
            @select="settingId"  />
        <van-popup v-model="show" closeable position="bottom" :style="{ height: '30%' }">
            <van-button style="margin-left:35%;width:30%;margin-top:15%;" @click="setMoren"
                color="linear-gradient(to right, #ff6034, #ee0a24)">
                设为默认
            </van-button>
        </van-popup>
    </div>
</template>

<script>
import axios from "axios";
export default {
    data() {
        return {
            chosenAddressId: '',
            list: [

            ],
            list1: [],
            show: false,
            sss:[],
        };
    },
    created() {
        this.getList();
    },
    methods: {
        onAdd() {
            this.$router.push({ path: '/addressEdit' })
        },
        onEdit(item) {
            console.log(item);
        },
        onClickLeft() {
            this.$router.push({ path: '/friends' })
        },
        getList() {
            axios({
                url: "/api/user/getAddress",
                method: "GET",
            }).then((res) => {
                this.list = res.data;
                console.log(this.list);
                this.list.forEach((v, i) => {
                    if (v.isDefault) {
                        this.chosenAddressId = v.id;
                    }
                })
            });
        },
        settingId(sss) {
            this.sss = sss;
            this.show=true
        },
        setMoren(){
            axios({
                url: "/api/user/updateSetting",
                method: "GET",
                params: {
                    receId: Number(this.sss.id),
                }
            }).then((res) => {
                this.getList();
                this.show=false
            });
        }
    },
}
</script>

<style>

</style>